package model;

import android.content.Context;
import android.location.LocationListener;
import android.util.Log;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.*;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.CoordinateConverter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


/**
 * Created by Administrator on 2014/11/26.
 */
public class LocationManager {
    // 定位相关
    LocationClient mLocClient;
    private LocationClient locationClient;
    private String getAppstr;
    public double lon;//经度
    private double lat;//纬度
    private  String address;

    public void getLocation(Context context) {
        // 定位初始化


        LocationClientOption option = new LocationClientOption();
        option.setAddrType("all");
        option.setCoorType("bd09ll");//返回的定位结果是百度经纬度，默认值gcj02
        option.setScanSpan(0);//设置发起定位请求的间隔时间为5000ms
        option.setOpenGps(true);// 打开gps
        locationClient = new LocationClient(context);
        locationClient.registerLocationListener(new BDLocationListener() {
            @Override
            public void onReceiveLocation(BDLocation bdLocation) {
                bdLocation.getAddrStr();
                lon = bdLocation.getLongitude();
                lat = bdLocation.getLatitude();
                address = bdLocation.getAddrStr();
                Log.d("getaaa",address+"aaa");
                
            }

            @Override
            public void onReceivePoi(BDLocation bdLocation) {

            }

        });
        locationClient.setLocOption(option);
        locationClient.start();
        locationClient.requestLocation();

    }
    public LatLng coordinateConversion(double lat,double lon){

        Log.d("desLatlng OLD",lat +"  " + lon);
        CoordinateConverter converter  = new CoordinateConverter();
        converter.from(CoordinateConverter.CoordType.COMMON);
        // sourceLatLng待转换坐标
        converter.coord(new LatLng(lat,lon));
        LatLng desLatLng = converter.convert();
        return desLatLng;


    }


    public double getLat() {
        Log.d("getaaa","getLat");
        return lat;
    }

    public double getLon() {

        return lon;
    }

    public String getAddress() {
        Log.d("getaaa","getAddress");
        return address;
    }
}
